   
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class CharlieView extends JFrame implements View {
  // Anfang Attribute
  private JButton Feld1 = new JButton();
  private JButton Feld2 = new JButton();
  private JButton Feld3 = new JButton();
  private JButton Feld4 = new JButton();
  private JButton Feld5 = new JButton();
  private JButton Feld6 = new JButton();
  private JButton Feld7 = new JButton();
  private JButton Feld8 = new JButton();
  private JButton Feld9 = new JButton();
  private JLabel Textfeld = new JLabel();
  Controller controller;
  // Ende Attribute
  
  public CharlieView(String title) { 
    // Frame-Initialisierung
    super(title);
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    int frameWidth = 300; 
    int frameHeight = 300;
    setSize(frameWidth, frameHeight);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (d.width - getSize().width) / 2;
    int y = (d.height - getSize().height) / 2;
    setLocation(x, y);
    setResizable(false);
    Container cp = getContentPane();
    cp.setLayout(null);
    // Anfang Komponenten
    
    Feld1.setBounds(24, 24, 33, 33);
    Feld1.setText("");
    Feld1.setMargin(new Insets(2, 2, 2, 2));
    Feld1.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent evt) { 
        Feld1_ActionPerformed(evt);
      }
    });
    cp.add(Feld1);
    Feld2.setBounds(72, 24, 33, 33);
    Feld2.setText("");
    Feld2.setMargin(new Insets(2, 2, 2, 2));
    Feld2.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent evt) { 
        Feld2_ActionPerformed(evt);
      }
    });
    cp.add(Feld2);
    Feld3.setBounds(120, 24, 33, 33);
    Feld3.setText("");
    Feld3.setMargin(new Insets(2, 2, 2, 2));
    Feld3.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent evt) { 
        Feld3_ActionPerformed(evt);
      }
    });
    cp.add(Feld3);
    Feld4.setBounds(24, 72, 33, 33);
    Feld4.setText("");
    Feld4.setMargin(new Insets(2, 2, 2, 2));
    Feld4.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent evt) { 
        Feld4_ActionPerformed(evt);
      }
    });
    cp.add(Feld4);
    Feld5.setBounds(72, 72, 33, 33);
    Feld5.setText("");
    Feld5.setMargin(new Insets(2, 2, 2, 2));
    Feld5.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent evt) { 
        Feld5_ActionPerformed(evt);
      }
    });
    cp.add(Feld5);
    Feld6.setBounds(120, 72, 33, 33);
    Feld6.setText("");
    Feld6.setMargin(new Insets(2, 2, 2, 2));
    Feld6.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent evt) { 
        Feld6_ActionPerformed(evt);
      }
    });
    cp.add(Feld6);
    Feld8.setBounds(72, 120, 33, 33);
    Feld8.setText("");
    Feld8.setMargin(new Insets(2, 2, 2, 2));
    Feld8.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent evt) { 
        Feld8_ActionPerformed(evt);
      }
    });
    cp.add(Feld8);
    Feld7.setBounds(24, 120, 33, 33);
    Feld7.setText("");
    Feld7.setMargin(new Insets(2, 2, 2, 2));
    Feld7.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent evt) { 
        Feld7_ActionPerformed(evt);
      }
    });
    cp.add(Feld7);
    Feld9.setBounds(120, 120, 33, 33);
    Feld9.setText("");
    Feld9.setMargin(new Insets(2, 2, 2, 2));
    Feld9.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent evt) { 
        Feld9_ActionPerformed(evt);
      }
    });
    cp.add(Feld9);
    Textfeld.setBounds(24, 184, 131, 33);
    Textfeld.setText("");
    cp.add(Textfeld);
    // Ende Komponenten
    
    setVisible(true);
  } // end of public CharlieView
  
  // Anfang Methoden
  
  public static void main(String[] args) {
    new CharlieView("CharlieView");
  } // end of main
  
  public void Feld1_ActionPerformed(ActionEvent evt) {
   controller.buttonGedrueckt(0);
  } // end of Feld1_ActionPerformed

  public void Feld2_ActionPerformed(ActionEvent evt) {
    controller.buttonGedrueckt(1);
  } // end of Feld2_ActionPerformed

  public void Feld3_ActionPerformed(ActionEvent evt) {
     controller.buttonGedrueckt(2);
  } // end of Feld3_ActionPerformed

  public void Feld4_ActionPerformed(ActionEvent evt) {
     controller.buttonGedrueckt(3);
  } // end of Feld4_ActionPerformed

  public void Feld5_ActionPerformed(ActionEvent evt) {
     controller.buttonGedrueckt(4);
  } // end of Feld5_ActionPerformed

  public void Feld6_ActionPerformed(ActionEvent evt) {
     controller.buttonGedrueckt(5);
  } // end of Feld6_ActionPerformed

  public void Feld7_ActionPerformed(ActionEvent evt) {
     controller.buttonGedrueckt(6);
  } // end of Feld8_ActionPerformed

  public void Feld8_ActionPerformed(ActionEvent evt) {
      controller.buttonGedrueckt(7);
  } // end of Feld7_ActionPerformed

  public void Feld9_ActionPerformed(ActionEvent evt) {
     controller.buttonGedrueckt(8);
  } // end of Feld9_ActionPerformed

   
  public void controllerSetzen(Controller neuerController)
    {this.controller = neuerController; }
   
  public void spieler1Anzeigen(int a)
    {
        if (a == 0) Feld1.setText("X");
        if (a == 1) Feld2.setText("X");
        if (a == 2) Feld3.setText("X");
        if (a == 3) Feld4.setText("X");
        if (a == 4) Feld5.setText("X");
        if (a == 5) Feld6.setText("X");
        if (a == 6) Feld7.setText("X");
        if (a == 7) Feld8.setText("X");
        if (a == 8) Feld9.setText("X");
    }
    
  public void spieler2Anzeigen(int a)
    {
        if (a == 0) Feld1.setText("O");
        if (a == 1) Feld2.setText("O");
        if (a == 2) Feld3.setText("O");
        if (a == 3) Feld4.setText("O");
        if (a == 4) Feld5.setText("O");
        if (a == 5) Feld6.setText("O");
        if (a == 6) Feld7.setText("O");
        if (a == 7) Feld8.setText("O");
        if (a == 8) Feld9.setText("O");
    }
    
  public void kommentarAnzeigen(String text)
  {
      Textfeld.setText(text);
 } 
 
// Ende Methoden
} // end of class CharlieView
